***********************************
* Aticle: “They Own Our Country!” Voter Reaction to Anti-China Rhetoric: The Case of the Presidential Election in Brazil in 2018
* Author: Francisco Urdinez
* Journal: Electoral Studies
***********************************


*BODY OF THE TEXT

*load electoral data
clear all
use "electoral_data.dta", clear

*Figure 3. Electoral performance of Bolsonaro. Source: Superior Electoral Court of Brazil
** panel (a)
hist perc_bolsonaro, bin(50) percent
** panel (b)
hist bolsowin, discrete percent

*Table 2. Linear probability models of the effect of Chinese acquisitions on Bolsonaro’s electoral success
reg bolsowin  fdi_dummy  log_employment  pt_vote_share hdi import_shock log_crime log_evangelical  sizeagric sizemanuf sizemine   fdi_world_log,r
estimates store m1
reg bolsowin  ma_count greenfield_count  log_employment  pt_vote_share hdi import_shock log_crime log_evangelical  sizeagric sizemanuf sizemine   fdi_world_log,r
estimates store m2
reg bolsowin  log_ma log_green_fdi log_employment pt_vote_share hdi import_shock log_crime log_evangelical  sizeagric sizemanuf sizemine   fdi_world_log,r
estimates store m3
reg bolsowin    ma_shock_log green_shock_log log_employment   pt_vote_share hdi import_shock log_crime log_evangelical  sizeagric sizemanuf sizemine   fdi_world_log,r
estimates store m4

esttab m1 m2 m3 m4 , r2 se

*Table 3. Coarsened exact match to estimate the effect of Chinese acquisitions on Bolsonaro’s electoral success
drop if fdi_dummy==.
imb pt_vote_share  state  hdi  , treatment(fdi_dummy )
egen scode=group(state)
cem  state(#27) pt_vote_share(21 43 56 73) hdi(#4)  , treatment(fdi_dummy)

reg bolsowin  fdi_dummy    [iweight= cem_matched], r
 estimates store m1
reg bolsowin  ma_count    [iweight= cem_matched], r
estimates store m2
reg bolsowin  log_ma  [iweight= cem_matched], r
estimates store m3
reg bolsowin    ma_shock_log      [iweight= cem_matched], r
estimates store m4

esttab m1 m2 m3 m4 , r2 se

*Load survey data
clear all
use "survey_data.dta", clear 

*Table 4. Linear probability models to estimate voters attitudes towards China
reg china  ma_fdi_share ideology education sex income age i.state if vote_bolsonaro==1,  vce(r)
estimates store m1a
reg china  ma_fdi_share ideology education sex income age i.state if vote_bolsonaro==0,  vce(r)
estimates store m1b
reg chinese_fdi  ma_fdi_share ideology education sex income  age i.state  if vote_bolsonaro==1,  vce(r)
estimates store m2a
reg chinese_fdi  ma_fdi_share ideology education sex income  age i.state  if vote_bolsonaro==0,  vce(r)
estimates store m2b
esttab m1a m1b m2a m2b , r2 se 

*Figure 4. Word cloud of the most frequently used words to describe China
*(data was translated to English and plotted using R)

tab gut if vote_bolsonaro==1
tab gut if vote_bolsonaro==0


*APPENDIX
clear all
use "electoral_data.dta", clear

*Table B. Correlation matrix of independent variables and controls
pwcorr fdi_dummy  log_total_fdi_china log_ma ma_shock  pt_vote_share perc_poverty log_crime log_evangelical import_shock  sizeagric sizemanuf sizemine  population_log fdi_world_log

*Table C. Descriptive statistics of controlling variables
sum   pt_vote_share log_employment log_employment hdi log_evangelical  sizeagric sizemanuf sizemine  log_crime  import_shock fdi_world_log

*Table D. Minimal sensitivity analysis reporting and Figures B and C
ssc install sensemakr
sensemakr bolsowin  fdi_dummy  log_employment  pt_vote_share hdi import_shock log_crime log_evangelical  sizeagric sizemanuf sizemine   fdi_world_log, treat(fdi_dummy)  benchmark(pt_vote_share) contourplot tcontourplot

**Survey data
use "survey_data.dta", clear 

* Table E. Descriptive statistics of survey data
sum china chinese_fdi ma_fdi_share ideology income  sex education  age

*Table F. Geographical representation of survey data
tab state

* Table G. Correlation matrix of survey data
pwcorr china chinese_fdi ma_fdi_share ideology education sex income age




***********







 





